//
//  NSNull+IfNull.m
//  YingYingLiCai
//
//  Created by JianYe on 14-5-22.
//  Copyright (c) 2014年 YingYing. All rights reserved.
//

#import "NSNull+ExceptionHandle.h"

#define NSNullObjects @[@"",@0,@{},@[]]

@implementation NSNull (ExceptionHandle)
- (NSMethodSignature*)methodSignatureForSelector:(SEL)selector
{
    NSMethodSignature *signature = [super methodSignatureForSelector:selector];
    if (!signature) {
        for (NSObject *object in NSNullObjects) {
            signature = [object methodSignatureForSelector:selector];
            if (signature) {
                break;
            }
        }
    }
    return signature;
}

- (void)forwardInvocation:(NSInvocation *)anInvocation {
    SEL aSelector = [anInvocation selector];
    for (NSObject *object in NSNullObjects) {
        if ([object respondsToSelector:aSelector]) {
            [anInvocation invokeWithTarget:object];
            return;
        }
    }
    [self doesNotRecognizeSelector:aSelector];
} 
@end
